@extends('pc_admin.app')

@section('content')
    <link rel="stylesheet" href="/css/bootstrap.css">
    <link rel="stylesheet" href="/css/daterangepicker.css">
    <link rel="stylesheet" href="/css/mobileSelect.css">
    <link rel="stylesheet" href="/css/pc-system/data-out.css">
    <div class="mian-container">
        <div class="container-section weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <p>选择时间</p>
                </div>
                <div class="weui-cell__bd">
                    <p id="daterange-btn" class="choose-time">
                        <span><i class="icon iconfont icon-calendar1"></i> 日期选择</span>
                        <i class="icon iconfont icon-danxian-youjiantou-copy"></i>
                    </p>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <p>考核对象</p>
                </div>
                <div class="weui-cell__bd">
                    <p class="choose-person" id="trigger5"></p>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <p>绩效详情(多选)</p>
                </div>
                <div class="weui-cell__bd">
                    <div class="weui-flex">
                        <div class="weui-flex__item">
                            <input class="radio" type="checkbox" name="public" value="1">
                            <label class="label"></label>
                            <span>奖惩</span>
                        </div>
                        <div class="weui-flex__item">
                            <input class="radio" type="checkbox" name="public" value="2">
                            <label class="label"></label>
                            <span>出勤</span>
                        </div>
                        <div class="weui-flex__item">
                            <input class="radio" type="checkbox" name="public" value="3">
                            <label class="label"></label>
                            <span>业绩</span>
                        </div>
                    </div>
                </div>
            </div>
            {!! csrf_field() !!}
            <a href="javascript:void(0)" class="btn-out">导出</a>
        </div>
    </div>
<script src="/js/mobileSelect.js"></script>
<script src="/addons/moment.js"></script>
<script src="/addons/daterangepicker.js"></script>
<script>
    var poststartDate;//开始日期
    var postendDate;//结束日期
    var groupid;//部门id
    var uids;//选择的用户id
    $(document).ready(function () {
        $('.ranges_1 ul').remove();
        $('#daterange-btn').daterangepicker({
                    ranges: {
//                        '全部': [moment(), moment().subtract(-1, 'days')],
                        '今天': [moment(), moment()],
                        '明天': [moment(), moment().subtract(-1, 'days')],
                        '未来七天': [moment(),moment().subtract(-6, 'days')],
                        '未来30天': [moment(),moment().subtract(-29, 'days')],
                        '未来60天': [moment(),moment().subtract(-59, 'days'), ]
                    },
                    startDate: moment(),
                    endDate: moment()
                },
                function(start, end,label) {
                    //label:通过它来知道用户选择的是什么，传给后台进行相应的展示
                    console.log(label)
                    if(label=='全部'){
                        $('#daterange-btn span').html('全部');
                    }else if(label=='今天'){
                        $('#daterange-btn span').html(start.format('YYYY/MM/DD'));
                    }else if(label=='明天'){
                        $('#daterange-btn span').html(start.format('YYYY/MM/DD')+'-'+end.format('YYYY/MM/DD'));
                    }else if(label=='未来七天'){
                        $('#daterange-btn span').html(start.format('YYYY/MM/DD')+'-'+end.format('YYYY/MM/DD'));
                    }else if(label=='未来30天'){
                        $('#daterange-btn span').html(start.format('YYYY/MM/DD')+'-'+end.format('YYYY/MM/DD'));
                    }else if(label=='未来60天'){
                        $('#daterange-btn span').html(start.format('YYYY/MM/DD')+'-'+end.format('YYYY/MM/DD'));
                    }

                    poststartDate = start.format('YYYY-MM-DD');
                    postendDate = end.format('YYYY-MM-DD');
                    console.log(postendDate);
                    console.log(poststartDate);
                })



        var UplinkData = {!! $dep !!};
                /*[
                    {id:'1',value:'兰博基尼'},
                    {
                        id:'2',
                        value:'劳斯莱斯',
                        childs:[
                            {
                                id:'1',
                                value:'曜影'
                            },
                            {
                                id:'2',
                                value:'幻影'
                            },
                            {
                                id:'3',
                                value:'古思特'
                            },
                            {
                                id:'4',
                                value:'魅影'
                            }
                        ]
                    },
                    {
                        id:'3',
                        value:'宾利',
                        childs:[
                            {
                                id:'1',
                                value:'慕尚'
                            },
                            {
                                id:'2',
                                value:'欧陆'
                            }
                        ]
                    },
                    {
                        id:'4',
                        value:'法拉利',
                        childs:[
                            {
                                id:'1',
                                value:'LaFerrari'
                            },
                            {
                                id:'2',
                                value:'法拉利488'
                            },
                            {
                                id:'3',
                                value:'GTC4Lusso'
                            }
                        ]
                    },
                    {
                        id:'5',
                        value:'玛莎拉蒂',
                        childs:[
                            {
                                id:'1',
                                value:'总裁'
                            },
                            {
                                id:'2',
                                value:'玛莎拉蒂GT'
                            },
                            {
                                id:'3',
                                value:'Levante'
                            }
                        ]
                    }
                ];*/


        var mobileSelect5 = new MobileSelect({
            trigger: '#trigger5',
            title: '人员选择',
            wheels: [
                {data : UplinkData}
            ],
//            keyMap: {
//                id:'id',
//                value: 'title',
//                childs :'children'
//            },
            position: [2,0],//初始化定位
            transitionEnd:function(indexArr, data){
                //console.log(data);
            },
            callback:function(indexArr, data){
                console.log(data[0].id);
                groupid = data[0].id;
                uids = data[1].id;
            }
        });
        $('.btn-out').click(function () {
            var token = $('input[name=_token]').val();
            var ids = [];
            $(".weui-flex").find('input:checkbox').each(function() { //遍历所有复选框
                if ($(this).prop('checked') == true) {
                    console.log($(this).val()); //打印当前选中的复选框的值
                    ids.push($(this).val());
                }
            });
            if(ids.length == 0){
                alert('请选择导出的项目');
                return false;
            }
            if(poststartDate == undefined){
                alert('请选择开始时间');
                return false;
            }
            if(postendDate == undefined){
                alert('请选择结束时间');
                return false;
            }
            if(groupid == undefined){
                alert('请选择人员');
                return false;
            }
            //console.log($('#daterange-btn span').text());
            //console.log($('#trigger5').text());

            window.open('/sysadmin/user/export-thexcel?_token='+token+'&groupid='+groupid+'&uids='+uids+'&items='+JSON.stringify(ids)
                    +'&startDate='+poststartDate+'&endDate='+postendDate);
            $.ajax({
                'url': '/sysadmin/user/export-excel?_token='+token+'&groupid='+groupid+'&uids='+uids,
                'type': 'POST',
                'data': {'items':JSON.stringify(ids),'startDate':poststartDate,'endDate':postendDate},
                error: function (request) {
                    $.toast('网络错误',"text");
                },
                success: function (data) {
                    if (data.status == 'success') {
                        //$.toast("操作成功");
                    } else {
                        //$.toast(data.msg,"text");
                    }
                },
            });
        })
    })
</script>
@endsection